const db = require('../../models/index');
const DAO = require('../../dao/sql-option-dao');
const logger = require('../../utils/logger-util');
const Sort = db.sort;
const Article = db.article;
const Tags = db.tags;

// 创建分类
exports.create = async (req, res) => {
    const createInfo = req.body;
    let findSort = await Sort.findOne({ where: { 'sort_name':createInfo.sortName } });
    if(findSort && findSort.id) return res.sendResultAto(null, 605, '分类已存在！');
    DAO.create(Sort, createInfo, data => {
        res.sendResult(data);
    });
};

// 查询全部分类
exports.findAll = (req, res) => {
    const fAllInfo = req.body;
    DAO.list(Sort, fAllInfo, list => {
        res.sendResult(list);
    });
};

// 查询单个
exports.findOne = (req, res) => {
    const fOneInfo = req.body;
    DAO.findOne(Sort, fOneInfo, data => {
        res.sendResult(data);
    });
};

// 更新
exports.update = (req, res) => {
    const updateInfo = req.body;
    DAO.update(Sort, updateInfo, {id:updateInfo.id}, data => {
        res.sendResult(data);
    });
};

// 删除
exports.delete = (req, res) => {
    const deleteInfo = req.body;
    DAO.delete(Sort, { id:deleteInfo.id }, data => {
        res.sendResult(data);
    });
};

// 删除全部
exports.deleteAll = (req, res) => {
    const dAllInfo = req.body;
    DAO.deleteAll(Sort, data => {
        res.sendResult(data);
    });
};